var path = require('path');
var webpack = require('webpack');
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var env = process.env.NODE_ENV;

var config = {
    entry: {
        'admin': './admin/index.js',
        'consume': './consume/index.js'
    },
    module: {
        rules: [
            {
                test: /\.less$/,
                use: ExtractTextPlugin.extract({
                    fallback: "style-loader",
                    use: ['css-loader', 'less-loader']
                })
            },
            {
                test: /\.js/,
                exclude: /node_modules/,
                use: 'babel-loader'
            }
        ]
    },
    plugins: [
        new ExtractTextPlugin("styles.css")
    ],
    output: {
        path: path.join(__dirname, 'dist'),
        publicPath: '/dist',
        filename: '[name].bundle.js'
    }
};

if (env === 'product') {
    console.log(env)
    config.plugins.push(
        new webpack.optimize.UglifyJsPlugin({
            compress: {
                warnings: false,
                drop_console: false
            }
        }),
        new webpack.optimize.OccurrenceOrderPlugin()
    );
}

module.exports = config;
